#ifndef CLINE_SCAN_CPP
#define CLINE_SCAN_CPP

#include "CLineScan.h"

template <typename _FO, typename _PT>
 CLineScan<_FO,_PT>::CLineScan (point_t init, point_t end,_FO *_functor){
	int x = init[X], y = init[Y],
		x2 = end[X], y2 = end[Y];
	bool yLonger = false;
	int shortLen = y2-y;
	int longLen = x2-x;

	if (abs(shortLen)>abs(longLen)) {
		int swap = shortLen;
		shortLen = longLen;
		longLen = swap;
		yLonger = true;
		}

	int decInc;
	if (longLen == 0) decInc = 0;
	else decInc = (shortLen << 16) / longLen;

	if (yLonger) {
		if (longLen>0) {
			longLen += y;
			for (int j = 0x8000 + (x<<16); y <= longLen; ++y) {
				(*_functor)(point_t(j >> 16,y));
				j += decInc;
				}
			return;
			}
		longLen += y;
		for (int j = 0x8000 + (x<<16); y >= longLen; --y){
			(*_functor)(point_t(j >> 16,y));
			j -= decInc;
			}
		return;
		}

	if (longLen > 0){
		longLen += x;
		for (int j = 0x8000 + (y<<16); x <= longLen; ++x){
			(*_functor)(point_t(x,j >> 16));
			j += decInc;
			}
		return;
		}

	longLen += x;
	for (int j = 0x8000 + (y<<16); x >= longLen; --x){
		(*_functor)(point_t(x,j >> 16));
		j -= decInc;
		}
	}

#endif 
